package net.martinimix.bizact.validation;

import org.springframework.validation.AbstractBindingResult;
import org.springframework.validation.Errors;

import com.bluemartini.dna.DNAList;
import com.bluemartini.html.HTMLContext;

/**
 * Provides a Blue Martini form errors object.  This class is experimental.
 * 
 * @author Scott Rossillo
 *
 */
public final class BlueMartiniFormErrors extends AbstractBindingResult implements Errors {

	private static final long serialVersionUID = 1L;

	private final DNAList dnaIn;
	
	/**
	 * Creates a new form errors object.
	 */
	public BlueMartiniFormErrors(DNAList dnaIn) {
		super("formData");
		this.dnaIn = dnaIn;
	}
	
	/* (non-Javadoc)
	 * @see org.springframework.validation.AbstractBindingResult#getActualFieldValue(java.lang.String)
	 */
	protected Object getActualFieldValue(String fieldName) {
		
		final DNAList formValues = dnaIn.getList(HTMLContext.REQUEST_FORM_VALUES);
		
		return formValues.getString(fieldName);
	}

	/* (non-Javadoc)
	 * @see org.springframework.validation.AbstractBindingResult#getTarget()
	 */
	public Object getTarget() {
		
		return dnaIn.getList(HTMLContext.REQUEST_FORM_DATA);
	}

}
